{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Looking in indexes: http://mirrors.aliyun.com/pypi/simple/\n",
      "Requirement already satisfied: langchain in c:\\users\\rf.yin\\.conda\\envs\\pydantic-ai\\lib\\site-packages (0.3.19)\n",
      "Requirement already satisfied: langchain-core<1.0.0,>=0.3.35 in c:\\users\\rf.yin\\.conda\\envs\\pydantic-ai\\lib\\site-packages (from langchain) (0.3.39)\n",
      "Requirement already satisfied: langchain-text-splitters<1.0.0,>=0.3.6 in c:\\users\\rf.yin\\.conda\\envs\\pydantic-ai\\lib\\site-packages (from langchain) (0.3.6)\n",
      "Requirement already satisfied: langsmith<0.4,>=0.1.17 in c:\\users\\rf.yin\\.conda\\envs\\pydantic-ai\\lib\\site-packages (from langchain) (0.3.11)\n",
      "Requirement already satisfied: pydantic<3.0.0,>=2.7.4 in c:\\users\\rf.yin\\.conda\\envs\\pydantic-ai\\lib\\site-packages (from langchain) (2.10.6)\n",
      "Requirement already satisfied: SQLAlchemy<3,>=1.4 in c:\\users\\rf.yin\\.conda\\envs\\pydantic-ai\\lib\\site-packages (from langchain) (2.0.38)\n",
      "Requirement already satisfied: requests<3,>=2 in c:\\users\\rf.yin\\.conda\\envs\\pydantic-ai\\lib\\site-packages (from langchain) (2.32.3)\n",
      "Requirement already satisfied: PyYAML>=5.3 in c:\\users\\rf.yin\\.conda\\envs\\pydantic-ai\\lib\\site-packages (from langchain) (6.0.2)\n",
      "Requirement already satisfied: aiohttp<4.0.0,>=3.8.3 in c:\\users\\rf.yin\\.conda\\envs\\pydantic-ai\\lib\\site-packages (from langchain) (3.11.13)\n",
      "Requirement already satisfied: tenacity!=8.4.0,<10,>=8.1.0 in c:\\users\\rf.yin\\.conda\\envs\\pydantic-ai\\lib\\site-packages (from langchain) (9.0.0)\n",
      "Requirement already satisfied: numpy<2,>=1.26.4 in c:\\users\\rf.yin\\.conda\\envs\\pydantic-ai\\lib\\site-packages (from langchain) (1.26.4)\n",
      "Requirement already satisfied: aiohappyeyeballs>=2.3.0 in c:\\users\\rf.yin\\.conda\\envs\\pydantic-ai\\lib\\site-packages (from aiohttp<4.0.0,>=3.8.3->langchain) (2.4.6)\n",
      "Requirement already satisfied: aiosignal>=1.1.2 in c:\\users\\rf.yin\\.conda\\envs\\pydantic-ai\\lib\\site-packages (from aiohttp<4.0.0,>=3.8.3->langchain) (1.3.2)\n",
      "Requirement already satisfied: attrs>=17.3.0 in c:\\users\\rf.yin\\.conda\\envs\\pydantic-ai\\lib\\site-packages (from aiohttp<4.0.0,>=3.8.3->langchain) (25.1.0)\n",
      "Requirement already satisfied: frozenlist>=1.1.1 in c:\\users\\rf.yin\\.conda\\envs\\pydantic-ai\\lib\\site-packages (from aiohttp<4.0.0,>=3.8.3->langchain) (1.5.0)\n",
      "Requirement already satisfied: multidict<7.0,>=4.5 in c:\\users\\rf.yin\\.conda\\envs\\pydantic-ai\\lib\\site-packages (from aiohttp<4.0.0,>=3.8.3->langchain) (6.1.0)\n",
      "Requirement already satisfied: propcache>=0.2.0 in c:\\users\\rf.yin\\.conda\\envs\\pydantic-ai\\lib\\site-packages (from aiohttp<4.0.0,>=3.8.3->langchain) (0.3.0)\n",
      "Requirement already satisfied: yarl<2.0,>=1.17.0 in c:\\users\\rf.yin\\.conda\\envs\\pydantic-ai\\lib\\site-packages (from aiohttp<4.0.0,>=3.8.3->langchain) (1.18.3)\n",
      "Requirement already satisfied: jsonpatch<2.0,>=1.33 in c:\\users\\rf.yin\\.conda\\envs\\pydantic-ai\\lib\\site-packages (from langchain-core<1.0.0,>=0.3.35->langchain) (1.33)\n",
      "Requirement already satisfied: packaging<25,>=23.2 in c:\\users\\rf.yin\\.conda\\envs\\pydantic-ai\\lib\\site-packages (from langchain-core<1.0.0,>=0.3.35->langchain) (24.2)\n",
      "Requirement already satisfied: typing-extensions>=4.7 in c:\\users\\rf.yin\\.conda\\envs\\pydantic-ai\\lib\\site-packages (from langchain-core<1.0.0,>=0.3.35->langchain) (4.12.2)\n",
      "Requirement already satisfied: httpx<1,>=0.23.0 in c:\\users\\rf.yin\\.conda\\envs\\pydantic-ai\\lib\\site-packages (from langsmith<0.4,>=0.1.17->langchain) (0.28.1)\n",
      "Requirement already satisfied: orjson<4.0.0,>=3.9.14 in c:\\users\\rf.yin\\.conda\\envs\\pydantic-ai\\lib\\site-packages (from langsmith<0.4,>=0.1.17->langchain) (3.10.15)\n",
      "Requirement already satisfied: requests-toolbelt<2.0.0,>=1.0.0 in c:\\users\\rf.yin\\.conda\\envs\\pydantic-ai\\lib\\site-packages (from langsmith<0.4,>=0.1.17->langchain) (1.0.0)\n",
      "Requirement already satisfied: zstandard<0.24.0,>=0.23.0 in c:\\users\\rf.yin\\.conda\\envs\\pydantic-ai\\lib\\site-packages (from langsmith<0.4,>=0.1.17->langchain) (0.23.0)\n",
      "Requirement already satisfied: annotated-types>=0.6.0 in c:\\users\\rf.yin\\.conda\\envs\\pydantic-ai\\lib\\site-packages (from pydantic<3.0.0,>=2.7.4->langchain) (0.7.0)\n",
      "Requirement already satisfied: pydantic-core==2.27.2 in c:\\users\\rf.yin\\.conda\\envs\\pydantic-ai\\lib\\site-packages (from pydantic<3.0.0,>=2.7.4->langchain) (2.27.2)\n",
      "Requirement already satisfied: charset-normalizer<4,>=2 in c:\\users\\rf.yin\\.conda\\envs\\pydantic-ai\\lib\\site-packages (from requests<3,>=2->langchain) (3.4.1)\n",
      "Requirement already satisfied: idna<4,>=2.5 in c:\\users\\rf.yin\\.conda\\envs\\pydantic-ai\\lib\\site-packages (from requests<3,>=2->langchain) (3.10)\n",
      "Requirement already satisfied: urllib3<3,>=1.21.1 in c:\\users\\rf.yin\\.conda\\envs\\pydantic-ai\\lib\\site-packages (from requests<3,>=2->langchain) (2.3.0)\n",
      "Requirement already satisfied: certifi>=2017.4.17 in c:\\users\\rf.yin\\.conda\\envs\\pydantic-ai\\lib\\site-packages (from requests<3,>=2->langchain) (2025.1.31)\n",
      "Requirement already satisfied: greenlet!=0.4.17 in c:\\users\\rf.yin\\.conda\\envs\\pydantic-ai\\lib\\site-packages (from SQLAlchemy<3,>=1.4->langchain) (3.1.1)\n",
      "Requirement already satisfied: anyio in c:\\users\\rf.yin\\.conda\\envs\\pydantic-ai\\lib\\site-packages (from httpx<1,>=0.23.0->langsmith<0.4,>=0.1.17->langchain) (4.8.0)\n",
      "Requirement already satisfied: httpcore==1.* in c:\\users\\rf.yin\\.conda\\envs\\pydantic-ai\\lib\\site-packages (from httpx<1,>=0.23.0->langsmith<0.4,>=0.1.17->langchain) (1.0.7)\n",
      "Requirement already satisfied: h11<0.15,>=0.13 in c:\\users\\rf.yin\\.conda\\envs\\pydantic-ai\\lib\\site-packages (from httpcore==1.*->httpx<1,>=0.23.0->langsmith<0.4,>=0.1.17->langchain) (0.14.0)\n",
      "Requirement already satisfied: jsonpointer>=1.9 in c:\\users\\rf.yin\\.conda\\envs\\pydantic-ai\\lib\\site-packages (from jsonpatch<2.0,>=1.33->langchain-core<1.0.0,>=0.3.35->langchain) (3.0.0)\n",
      "Requirement already satisfied: sniffio>=1.1 in c:\\users\\rf.yin\\.conda\\envs\\pydantic-ai\\lib\\site-packages (from anyio->httpx<1,>=0.23.0->langsmith<0.4,>=0.1.17->langchain) (1.3.1)\n",
      "Looking in indexes: http://mirrors.aliyun.com/pypi/simple/\n",
      "Requirement already satisfied: langchain-core in c:\\users\\rf.yin\\.conda\\envs\\pydantic-ai\\lib\\site-packages (0.3.39)\n",
      "Requirement already satisfied: langgraph in c:\\users\\rf.yin\\.conda\\envs\\pydantic-ai\\lib\\site-packages (0.2.74)\n",
      "Requirement already satisfied: langsmith<0.4,>=0.1.125 in c:\\users\\rf.yin\\.conda\\envs\\pydantic-ai\\lib\\site-packages (from langchain-core) (0.3.11)\n",
      "Requirement already satisfied: tenacity!=8.4.0,<10.0.0,>=8.1.0 in c:\\users\\rf.yin\\.conda\\envs\\pydantic-ai\\lib\\site-packages (from langchain-core) (9.0.0)\n",
      "Requirement already satisfied: jsonpatch<2.0,>=1.33 in c:\\users\\rf.yin\\.conda\\envs\\pydantic-ai\\lib\\site-packages (from langchain-core) (1.33)\n",
      "Requirement already satisfied: PyYAML>=5.3 in c:\\users\\rf.yin\\.conda\\envs\\pydantic-ai\\lib\\site-packages (from langchain-core) (6.0.2)\n",
      "Requirement already satisfied: packaging<25,>=23.2 in c:\\users\\rf.yin\\.conda\\envs\\pydantic-ai\\lib\\site-packages (from langchain-core) (24.2)\n",
      "Requirement already satisfied: typing-extensions>=4.7 in c:\\users\\rf.yin\\.conda\\envs\\pydantic-ai\\lib\\site-packages (from langchain-core) (4.12.2)\n",
      "Requirement already satisfied: pydantic<3.0.0,>=2.5.2 in c:\\users\\rf.yin\\.conda\\envs\\pydantic-ai\\lib\\site-packages (from langchain-core) (2.10.6)\n",
      "Requirement already satisfied: langgraph-checkpoint<3.0.0,>=2.0.10 in c:\\users\\rf.yin\\.conda\\envs\\pydantic-ai\\lib\\site-packages (from langgraph) (2.0.16)\n",
      "Requirement already satisfied: langgraph-sdk<0.2.0,>=0.1.42 in c:\\users\\rf.yin\\.conda\\envs\\pydantic-ai\\lib\\site-packages (from langgraph) (0.1.53)\n",
      "Requirement already satisfied: jsonpointer>=1.9 in c:\\users\\rf.yin\\.conda\\envs\\pydantic-ai\\lib\\site-packages (from jsonpatch<2.0,>=1.33->langchain-core) (3.0.0)\n",
      "Requirement already satisfied: msgpack<2.0.0,>=1.1.0 in c:\\users\\rf.yin\\.conda\\envs\\pydantic-ai\\lib\\site-packages (from langgraph-checkpoint<3.0.0,>=2.0.10->langgraph) (1.1.0)\n",
      "Requirement already satisfied: httpx>=0.25.2 in c:\\users\\rf.yin\\.conda\\envs\\pydantic-ai\\lib\\site-packages (from langgraph-sdk<0.2.0,>=0.1.42->langgraph) (0.28.1)\n",
      "Requirement already satisfied: orjson>=3.10.1 in c:\\users\\rf.yin\\.conda\\envs\\pydantic-ai\\lib\\site-packages (from langgraph-sdk<0.2.0,>=0.1.42->langgraph) (3.10.15)\n",
      "Requirement already satisfied: requests<3,>=2 in c:\\users\\rf.yin\\.conda\\envs\\pydantic-ai\\lib\\site-packages (from langsmith<0.4,>=0.1.125->langchain-core) (2.32.3)\n",
      "Requirement already satisfied: requests-toolbelt<2.0.0,>=1.0.0 in c:\\users\\rf.yin\\.conda\\envs\\pydantic-ai\\lib\\site-packages (from langsmith<0.4,>=0.1.125->langchain-core) (1.0.0)\n",
      "Requirement already satisfied: zstandard<0.24.0,>=0.23.0 in c:\\users\\rf.yin\\.conda\\envs\\pydantic-ai\\lib\\site-packages (from langsmith<0.4,>=0.1.125->langchain-core) (0.23.0)\n",
      "Requirement already satisfied: annotated-types>=0.6.0 in c:\\users\\rf.yin\\.conda\\envs\\pydantic-ai\\lib\\site-packages (from pydantic<3.0.0,>=2.5.2->langchain-core) (0.7.0)\n",
      "Requirement already satisfied: pydantic-core==2.27.2 in c:\\users\\rf.yin\\.conda\\envs\\pydantic-ai\\lib\\site-packages (from pydantic<3.0.0,>=2.5.2->langchain-core) (2.27.2)\n",
      "Requirement already satisfied: anyio in c:\\users\\rf.yin\\.conda\\envs\\pydantic-ai\\lib\\site-packages (from httpx>=0.25.2->langgraph-sdk<0.2.0,>=0.1.42->langgraph) (4.8.0)\n",
      "Requirement already satisfied: certifi in c:\\users\\rf.yin\\.conda\\envs\\pydantic-ai\\lib\\site-packages (from httpx>=0.25.2->langgraph-sdk<0.2.0,>=0.1.42->langgraph) (2025.1.31)\n",
      "Requirement already satisfied: httpcore==1.* in c:\\users\\rf.yin\\.conda\\envs\\pydantic-ai\\lib\\site-packages (from httpx>=0.25.2->langgraph-sdk<0.2.0,>=0.1.42->langgraph) (1.0.7)\n",
      "Requirement already satisfied: idna in c:\\users\\rf.yin\\.conda\\envs\\pydantic-ai\\lib\\site-packages (from httpx>=0.25.2->langgraph-sdk<0.2.0,>=0.1.42->langgraph) (3.10)\n",
      "Requirement already satisfied: h11<0.15,>=0.13 in c:\\users\\rf.yin\\.conda\\envs\\pydantic-ai\\lib\\site-packages (from httpcore==1.*->httpx>=0.25.2->langgraph-sdk<0.2.0,>=0.1.42->langgraph) (0.14.0)\n",
      "Requirement already satisfied: charset-normalizer<4,>=2 in c:\\users\\rf.yin\\.conda\\envs\\pydantic-ai\\lib\\site-packages (from requests<3,>=2->langsmith<0.4,>=0.1.125->langchain-core) (3.4.1)\n",
      "Requirement already satisfied: urllib3<3,>=1.21.1 in c:\\users\\rf.yin\\.conda\\envs\\pydantic-ai\\lib\\site-packages (from requests<3,>=2->langsmith<0.4,>=0.1.125->langchain-core) (2.3.0)\n",
      "Requirement already satisfied: sniffio>=1.1 in c:\\users\\rf.yin\\.conda\\envs\\pydantic-ai\\lib\\site-packages (from anyio->httpx>=0.25.2->langgraph-sdk<0.2.0,>=0.1.42->langgraph) (1.3.1)\n",
      "Looking in indexes: http://mirrors.aliyun.com/pypi/simple/\n",
      "Requirement already satisfied: langchain-openai in c:\\users\\rf.yin\\.conda\\envs\\pydantic-ai\\lib\\site-packages (0.3.7)\n",
      "Requirement already satisfied: langchain-core<1.0.0,>=0.3.39 in c:\\users\\rf.yin\\.conda\\envs\\pydantic-ai\\lib\\site-packages (from langchain-openai) (0.3.39)\n",
      "Requirement already satisfied: openai<2.0.0,>=1.58.1 in c:\\users\\rf.yin\\.conda\\envs\\pydantic-ai\\lib\\site-packages (from langchain-openai) (1.61.1)\n",
      "Requirement already satisfied: tiktoken<1,>=0.7 in c:\\users\\rf.yin\\.conda\\envs\\pydantic-ai\\lib\\site-packages (from langchain-openai) (0.9.0)\n",
      "Requirement already satisfied: langsmith<0.4,>=0.1.125 in c:\\users\\rf.yin\\.conda\\envs\\pydantic-ai\\lib\\site-packages (from langchain-core<1.0.0,>=0.3.39->langchain-openai) (0.3.11)\n",
      "Requirement already satisfied: tenacity!=8.4.0,<10.0.0,>=8.1.0 in c:\\users\\rf.yin\\.conda\\envs\\pydantic-ai\\lib\\site-packages (from langchain-core<1.0.0,>=0.3.39->langchain-openai) (9.0.0)\n",
      "Requirement already satisfied: jsonpatch<2.0,>=1.33 in c:\\users\\rf.yin\\.conda\\envs\\pydantic-ai\\lib\\site-packages (from langchain-core<1.0.0,>=0.3.39->langchain-openai) (1.33)\n",
      "Requirement already satisfied: PyYAML>=5.3 in c:\\users\\rf.yin\\.conda\\envs\\pydantic-ai\\lib\\site-packages (from langchain-core<1.0.0,>=0.3.39->langchain-openai) (6.0.2)\n",
      "Requirement already satisfied: packaging<25,>=23.2 in c:\\users\\rf.yin\\.conda\\envs\\pydantic-ai\\lib\\site-packages (from langchain-core<1.0.0,>=0.3.39->langchain-openai) (24.2)\n",
      "Requirement already satisfied: typing-extensions>=4.7 in c:\\users\\rf.yin\\.conda\\envs\\pydantic-ai\\lib\\site-packages (from langchain-core<1.0.0,>=0.3.39->langchain-openai) (4.12.2)\n",
      "Requirement already satisfied: pydantic<3.0.0,>=2.5.2 in c:\\users\\rf.yin\\.conda\\envs\\pydantic-ai\\lib\\site-packages (from langchain-core<1.0.0,>=0.3.39->langchain-openai) (2.10.6)\n",
      "Requirement already satisfied: anyio<5,>=3.5.0 in c:\\users\\rf.yin\\.conda\\envs\\pydantic-ai\\lib\\site-packages (from openai<2.0.0,>=1.58.1->langchain-openai) (4.8.0)\n",
      "Requirement already satisfied: distro<2,>=1.7.0 in c:\\users\\rf.yin\\.conda\\envs\\pydantic-ai\\lib\\site-packages (from openai<2.0.0,>=1.58.1->langchain-openai) (1.9.0)\n",
      "Requirement already satisfied: httpx<1,>=0.23.0 in c:\\users\\rf.yin\\.conda\\envs\\pydantic-ai\\lib\\site-packages (from openai<2.0.0,>=1.58.1->langchain-openai) (0.28.1)\n",
      "Requirement already satisfied: jiter<1,>=0.4.0 in c:\\users\\rf.yin\\.conda\\envs\\pydantic-ai\\lib\\site-packages (from openai<2.0.0,>=1.58.1->langchain-openai) (0.8.2)\n",
      "Requirement already satisfied: sniffio in c:\\users\\rf.yin\\.conda\\envs\\pydantic-ai\\lib\\site-packages (from openai<2.0.0,>=1.58.1->langchain-openai) (1.3.1)\n",
      "Requirement already satisfied: tqdm>4 in c:\\users\\rf.yin\\.conda\\envs\\pydantic-ai\\lib\\site-packages (from openai<2.0.0,>=1.58.1->langchain-openai) (4.67.1)\n",
      "Requirement already satisfied: regex>=2022.1.18 in c:\\users\\rf.yin\\.conda\\envs\\pydantic-ai\\lib\\site-packages (from tiktoken<1,>=0.7->langchain-openai) (2024.11.6)\n",
      "Requirement already satisfied: requests>=2.26.0 in c:\\users\\rf.yin\\.conda\\envs\\pydantic-ai\\lib\\site-packages (from tiktoken<1,>=0.7->langchain-openai) (2.32.3)\n",
      "Requirement already satisfied: idna>=2.8 in c:\\users\\rf.yin\\.conda\\envs\\pydantic-ai\\lib\\site-packages (from anyio<5,>=3.5.0->openai<2.0.0,>=1.58.1->langchain-openai) (3.10)\n",
      "Requirement already satisfied: certifi in c:\\users\\rf.yin\\.conda\\envs\\pydantic-ai\\lib\\site-packages (from httpx<1,>=0.23.0->openai<2.0.0,>=1.58.1->langchain-openai) (2025.1.31)\n",
      "Requirement already satisfied: httpcore==1.* in c:\\users\\rf.yin\\.conda\\envs\\pydantic-ai\\lib\\site-packages (from httpx<1,>=0.23.0->openai<2.0.0,>=1.58.1->langchain-openai) (1.0.7)\n",
      "Requirement already satisfied: h11<0.15,>=0.13 in c:\\users\\rf.yin\\.conda\\envs\\pydantic-ai\\lib\\site-packages (from httpcore==1.*->httpx<1,>=0.23.0->openai<2.0.0,>=1.58.1->langchain-openai) (0.14.0)\n",
      "Requirement already satisfied: jsonpointer>=1.9 in c:\\users\\rf.yin\\.conda\\envs\\pydantic-ai\\lib\\site-packages (from jsonpatch<2.0,>=1.33->langchain-core<1.0.0,>=0.3.39->langchain-openai) (3.0.0)\n",
      "Requirement already satisfied: orjson<4.0.0,>=3.9.14 in c:\\users\\rf.yin\\.conda\\envs\\pydantic-ai\\lib\\site-packages (from langsmith<0.4,>=0.1.125->langchain-core<1.0.0,>=0.3.39->langchain-openai) (3.10.15)\n",
      "Requirement already satisfied: requests-toolbelt<2.0.0,>=1.0.0 in c:\\users\\rf.yin\\.conda\\envs\\pydantic-ai\\lib\\site-packages (from langsmith<0.4,>=0.1.125->langchain-core<1.0.0,>=0.3.39->langchain-openai) (1.0.0)\n",
      "Requirement already satisfied: zstandard<0.24.0,>=0.23.0 in c:\\users\\rf.yin\\.conda\\envs\\pydantic-ai\\lib\\site-packages (from langsmith<0.4,>=0.1.125->langchain-core<1.0.0,>=0.3.39->langchain-openai) (0.23.0)\n",
      "Requirement already satisfied: annotated-types>=0.6.0 in c:\\users\\rf.yin\\.conda\\envs\\pydantic-ai\\lib\\site-packages (from pydantic<3.0.0,>=2.5.2->langchain-core<1.0.0,>=0.3.39->langchain-openai) (0.7.0)\n",
      "Requirement already satisfied: pydantic-core==2.27.2 in c:\\users\\rf.yin\\.conda\\envs\\pydantic-ai\\lib\\site-packages (from pydantic<3.0.0,>=2.5.2->langchain-core<1.0.0,>=0.3.39->langchain-openai) (2.27.2)\n",
      "Requirement already satisfied: charset-normalizer<4,>=2 in c:\\users\\rf.yin\\.conda\\envs\\pydantic-ai\\lib\\site-packages (from requests>=2.26.0->tiktoken<1,>=0.7->langchain-openai) (3.4.1)\n",
      "Requirement already satisfied: urllib3<3,>=1.21.1 in c:\\users\\rf.yin\\.conda\\envs\\pydantic-ai\\lib\\site-packages (from requests>=2.26.0->tiktoken<1,>=0.7->langchain-openai) (2.3.0)\n",
      "Requirement already satisfied: colorama in c:\\users\\rf.yin\\.conda\\envs\\pydantic-ai\\lib\\site-packages (from tqdm>4->openai<2.0.0,>=1.58.1->langchain-openai) (0.4.6)\n",
      "Looking in indexes: http://mirrors.aliyun.com/pypi/simple/\n",
      "Requirement already satisfied: pydantic in c:\\users\\rf.yin\\.conda\\envs\\pydantic-ai\\lib\\site-packages (2.10.6)\n",
      "Requirement already satisfied: annotated-types>=0.6.0 in c:\\users\\rf.yin\\.conda\\envs\\pydantic-ai\\lib\\site-packages (from pydantic) (0.7.0)\n",
      "Requirement already satisfied: pydantic-core==2.27.2 in c:\\users\\rf.yin\\.conda\\envs\\pydantic-ai\\lib\\site-packages (from pydantic) (2.27.2)\n",
      "Requirement already satisfied: typing-extensions>=4.12.2 in c:\\users\\rf.yin\\.conda\\envs\\pydantic-ai\\lib\\site-packages (from pydantic) (4.12.2)\n"
     ]
    }
   ],
   "source": [
    "! pip install langchain\n",
    "! pip install langchain-core langgraph\n",
    "\n",
    "! pip install langchain-openai\n",
    "\n",
    "! pip install pydantic"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Hello, world!\n"
     ]
    }
   ],
   "source": [
    "from langchain_core.prompts import ChatPromptTemplate\n",
    "from langchain_openai import ChatOpenAI\n",
    "from langchain_core.messages import HumanMessage\n",
    "from pydantic import BaseModel, Field\n",
    "\n",
    "from pydantic import BaseModel, Field\n",
    "from typing import Optional, List, Literal\n",
    "\n",
    "class NovelSegment(BaseModel):\n",
    "    \"\"\"表示小说片段的最小处理单元\"\"\"\n",
    "    text: str = Field(..., description=\"处理后的文本内容\")\n",
    "    segment_type: Literal[\"旁白\", \"对话\"] = Field(\n",
    "        ..., \n",
    "        description=\"文本类型：旁白用于场景描述，对话表示人物发言\",\n",
    "        examples=[\"旁白\", \"对话\"]\n",
    "    )\n",
    "    speaker: Optional[str] = Field(\n",
    "        None,\n",
    "        description=\"说话角色名称（仅对话类型有效）\",\n",
    "        examples=[\"李静芷\", \"方娉\"]\n",
    "    )\n",
    "    emotion: Optional[str] = Field(\n",
    "        None,\n",
    "        description=\"情感特征标注（使用预定义情感词典）\",\n",
    "        examples=[\"焦虑\", \"期待\"],\n",
    "        json_schema_extra={\n",
    "            \"enum\": [\"快乐\", \"悲伤\", \"愤怒\", \"恐惧\", \"惊讶\", \"焦虑\", \n",
    "                    \"羞愧\", \"自豪\", \"嫉妒\", \"爱\", \"失望\", \"困惑\", \n",
    "                    \"希望\", \"绝望\", \"同情\", \"厌恶\", \"感激\", \"无聊\",\n",
    "                    \"兴奋\", \"孤独\", \"内疚\", \"骄傲\", \"谦卑\", \"渴望\",\n",
    "                    \"满足\", \"好奇\", \"紧张\", \"宽慰\", \"疲惫\", \"振奋\"]\n",
    "        }\n",
    "    )\n",
    "\n",
    "class ProcessedParagraph(BaseModel):\n",
    "    \"\"\"处理后的完整段落结构\"\"\"\n",
    "    original_text: str = Field(\n",
    "        ...,\n",
    "        description=\"原始段落文本（保持原文完整性）\",\n",
    "        min_length=10\n",
    "    )\n",
    "    segments: List[NovelSegment] = Field(\n",
    "        ...,\n",
    "        description=\"结构化处理后的文本片段列表\",\n",
    "        min_items=1\n",
    "    )\n",
    "\n",
    "class AudiobookScript(BaseModel):\n",
    "    \"\"\"有声书脚本的完整数据结构\"\"\"\n",
    "    source_content: str = Field(\n",
    "        ...,\n",
    "        description=\"原始输入文本全文\",\n",
    "        min_length=100\n",
    "    )\n",
    "    processed_content: List[ProcessedParagraph] = Field(\n",
    "        ...,\n",
    "        description=\"结构化处理结果列表\",\n",
    "        min_items=1\n",
    "    )"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 任务说明\n",
    "你是一个专业的有声书脚本编剧，请将输入的小说段落按照以下要求转换为结构化脚本数据：\n",
    "\n",
    "## 处理规则\n",
    "1. **段落拆分**：\n",
    "- 保持原始段落完整性，每个`<p>`标签内容视为独立段落\n",
    "- 按以下逻辑拆分文本片段：\n",
    "  - 旁白：场景描述/非对话内容（使用\"旁白\"类型）\n",
    "  - 对话：包含对话引导符号（如“「」”““””等）或明确说话主体的内容\n",
    "\n",
    "2. **对话标注**：\n",
    "- 必须提取说话人（例：\"李静芷\"）\n",
    "- 必须标注情感标签（从预定义列表选择）\n",
    "- 多人对话需拆分独立片段\n",
    "\n",
    "3. **格式要求**：\n",
    "- 严格使用提供的JSON Schema\n",
    "- 情感标注必须使用指定枚举值\n",
    "- 旁白片段禁止包含speaker字段\n",
    "- 保留原始文本标点符号\n",
    "\n",
    "## 输出示例\n",
    "```json\n",
    "{\n",
    "  \"source_content\": \"原文内容...\",\n",
    "  \"processed_content\": [\n",
    "    {\n",
    "      \"original_text\": \"「方娉，你脸色不太好...」李静芷递过一杯热茶，窗外的雨声渐渐密集起来。\",\n",
    "      \"segments\": [\n",
    "        {\n",
    "          \"text\": \"「方娉，你脸色不太好...」\",\n",
    "          \"segment_type\": \"对话\",\n",
    "          \"speaker\": \"李静芷\",\n",
    "          \"emotion\": \"关切\"\n",
    "        },\n",
    "        {\n",
    "          \"text\": \"递过一杯热茶，窗外的雨声渐渐密集起来。\",\n",
    "          \"segment_type\": \"旁白\"\n",
    "        }\n",
    "      ]\n",
    "    }\n",
    "  ]\n",
    "}```\n",
    "## 输入文本\n",
    "{{ 用户输入的小说文本 }}\n",
    "\n",
    "## 特别注意\n",
    "- 请返回纯JSON格式，不要使用markdown代码块包裹\n",
    "- 情感标注必须严格使用预定义枚举值\n",
    "- 对话必须同时包含speaker和emotion字段\n",
    "- 确保JSON格式能通过pydantic校验"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "pydantic-ai",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.11"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
